<template>
	<view class="memberInvite">
		<uni-nav-bar :border="false" background-color="#5577fa" color="#fff" left-icon="left" title="邀请码"
			@clickLeft="back" />
		<view class="memberInvite_box">
			<image class="memberInvite_img" v-if="res" :src="res.img" mode="widthFix" @click='saveImgToLocal()'></image>
			<view class="memberInvite_baocuen">
				点击图片保存
			</view>
		</view>
	</view>
</template>

<script>
	import {
		commission_qrcode
	} from '@/api/mine.js'
	export default {
		data() {
			return {
				openid: '',
				res: ''
			}
		},
		onLoad() {
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data;
					this.showMemberInviteFun();
				}
			});
		},
		onShow() {},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			async showMemberInviteFun() {
				let data = await commission_qrcode(this.openid);
				this.res = data.result;
			},
			saveImgToLocal() {
				console.log(this.res.img);
				uni.downloadFile({
					url: this.res.img, //图片地址
					success: (res) => {
						console.log(res)
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function() {
									uni.showToast({
										title: "保存成功",
										icon: "success"
									});
								},
								fail: function() {
									uni.showToast({
										title: "保存失败",
										icon: "none"
									});
								}
							});
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.memberInvite {
		height: 100vh;
		width: 100%;
		display: flex;
		flex-direction: column;
		padding-top: var(--status-bar-height);



		.memberInvite_box {
			flex: 1;
			background-color: #7161F5;

			.memberInvite_img {
				width: 100%;
				// height: 100%;
			}

			.memberInvite_baocuen {
				width: 100%;
				color: #fff;
				text-align: center;
			}

		}

	}
</style>